package com.tarena.lbs.basic.web.rpc;

import com.tarena.lbs.basic.api.BasicApi;
import com.tarena.lbs.basic.web.service.AdminService;
import com.tarena.lbs.basic.web.service.UserGroupService;
import com.tarena.lbs.pojo.basic.dto.AdminDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@DubboService
@Component
@Slf4j
public class BasicApiImpl implements BasicApi {
    @Autowired
    private AdminService adminService;
    @Autowired
    private UserGroupService userGroupService;
    @Override
    public AdminDTO getAdminDetail(Integer adminId) {
        //为了不向外抛出异常 异常内部效果
        AdminDTO adminDto=null;
        try{
            adminDto=adminService.detail(adminId);
        }catch (Exception e){
            log.error("远程调用查询商家账号详情失败",e);
        }
        return adminDto;
    }

    @Override
    public List<Integer> getUserGroupIds(Integer userId, Integer businessId) {
        log.info("查询用户:{}所属的商家范围:{}的人群列表",userId);
        List<Integer> userGroupIds=null;
        try{
            userGroupIds=userGroupService.getUserGroupIds(userId,businessId);
        }catch (Exception e){
            log.error("查询用户所属人群失败,userId:{},businessId:{}",userId,businessId,e);
        }
        return userGroupIds;
    }
}
